// 添加活动组件
<template>
    <div class="box" v-show="isShow">
        <div class="val">
            <div class="title"><i>添加活动</i><i @click="exit">x</i></div>
            <ul>
                <li class="active-title">
                    <span>活动标题:&emsp;</span>
                    <input type="text" name="" id="" v-model="activeTltle">
                </li>
                <li class="begin-time">
                    <span>开始时间:&emsp;</span>
                    <div>
                        <el-date-picker v-model="valueData1" type="week" format="YYYY/MM/DD" placeholder="请选择时间" />
                    </div>
                </li>
                <li class="end-time">
                    <span>结束时间:&emsp;</span>
                    <div>
                        <el-date-picker v-model="valueData2" type="week" format="YYYY/MM/DD" placeholder="请选择时间" />
                    </div>
                </li>
                <li>
                    <span>上线/下线&emsp;</span>
                    <div class="checkradio">
                        <el-radio-group v-model="radio">
                            <el-radio label="1" size="large">上线</el-radio>
                            <el-radio label="2" size="large">下线</el-radio>
                        </el-radio-group>
                    </div>
                </li>
            </ul>
            <div class="bottom-btn">
                <button @click="exit">取 消</button>
                <el-button text @click="open">确 认</el-button>
            </div>
        </div>

    </div>
</template>

<script lang="ts" setup>
import { ref, defineProps, defineEmits, watch } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus'
import {flash} from '../../request/api'
import { falshstore } from '../../stores/Flash'
let activeTltle = ref('')  //活动标题
let radio = ref('1')  // 上下线选择器
let valueData1 = ref('')  // 日期选择器 1
let valueData2 = ref('')  // 日期选择器 2
const open = () => {
    ElMessageBox.confirm(
        '确认添加这个活动吗',
        '确认信息',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            flash.FlashCreate({
                "createTime": new Date(),
                "endDate": valueData1.value,
                "id": 0,
                "startDate": valueData2.value,
                "status": radio.value,
                "title": activeTltle.value
            }).then(() => {
                // 触发隔壁的更新函数
                falshstore().setA++
                emit("update:isShow", false) //关闭显示

            })
            ElMessage({
                type: 'success',
                message: '添加信息成功',
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '取消添加',
            })
        })
}


let props = defineProps<{ isShow: boolean, state: any }>() // 监听带来的变化
watch(props, (nweProps) => {

    activeTltle.value = nweProps.state.title
    radio.value = nweProps.state.chose ? '1' : '0'
    valueData1.value = nweProps.state.begintime
    valueData2.value = nweProps.state.endtime

})


const emit = defineEmits<{
    (e: 'update:isShow', param: boolean): void,
    (e: 'update:state', params: any): void
}>()

let exit = () => {
    console.log('取消按钮');
    emit("update:isShow", false) //取消之后恢复初始值
    emit("update:state", {
        id: '',
        title: '',
        chose: false,
        begintime: '',
        endtime: ''
    })
}

let sure = () => {
    console.log('确认按钮', activeTltle.value, radio.value, valueData1.value, valueData2.value);
}

</script>
 
<style lang="scss" scoped>
.box {
    width: 100%;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    background-color: rgba(0, 0, 0, 0.6);
    animation: run 0.3s;

    .val {
        width: 700px;
        padding: 20px;
        background-color: rgb(255, 255, 255);

        .title {
            width: 100%;
            padding: 10px 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: #333;
            margin-bottom: 20px;

            i {
                font-weight: 400;
                font-size: 18px;

                &:nth-of-type(2) {
                    color: #999;
                    cursor: pointer;

                    &:hover {
                        color: rgb(64, 158, 255);
                    }
                }
            }
        }

        ul {
            padding: 0 30px;
            display: flex;
            flex-direction: column;
            align-items: start;
            color: #666;
            font-size: 14px;

            li {
                display: flex;
                align-items: center;
                margin: 10px 0;

                span {

                    padding: 10px;
                }

                input {
                    width: 230px;
                    height: 25px;
                    text-indent: 1em;
                    border-radius: 3px;
                    border: 1px solid #ccc;
                    outline: none;
                }
            }
        }

        .bottom-btn {
            display: flex;
            justify-content: flex-end;

            button {
                padding: 7px 15px;
                margin: 0px 6px;
                color: #666;
                border: 1px solid #999;
                border-radius: 3px;
                font-size: 12px;
                background-color: white;

                &:hover {
                    color: rgb(64, 158, 255);
                    border: 1px solid rgb(64, 158, 255);
                }

                &:nth-of-type(2) {
                    color: white;
                    border: 1px solid white;
                    background-color: rgb(64, 158, 255);
                }

            }
        }
    }
}

@keyframes run {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}
</style>